﻿using System;
using System.IO;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Navigation;
using MovieInfoSearchLib;
using System.Windows.Media.Imaging;
using System.Threading;
using System.Windows.Threading;
using System.ComponentModel;

namespace MovieInfoView
{
	public partial class MovieView
	{
		public MovieView()
		{
			this.InitializeComponent();

			// Insert code required on object creation below this point.
		}

        public void Clear()
        {
            this.setVidInfo(Movie.getBlankMovie());
        }

        public void ViewMovieInfo(Movie selected)
        {
            ThreadStart start = delegate()
            {
                Dispatcher.Invoke(DispatcherPriority.Normal,
                        new Action<Movie>(setVidInfo), selected);
            };
            new Thread(start).Start();
        }

        private void setVidInfo(Movie selected)
        {

            if (selected.imageURL != null)
                this.imgOrigionalImage.Source = new BitmapImage(new Uri(selected.imageURL));
            else
                this.imgOrigionalImage.Source = null;

            this.txtTitle.Text = selected.title + " (" + selected.releaseDate + ")";

            if (selected.tagline != "null")
                this.txtTagline.Text = selected.tagline;
            else
                this.txtTagline.Text = "";

            if(selected.plot != "null")
                this.txtSynopsis.Text = selected.plot;
            else
                this.txtSynopsis.Text = "";

            if(selected.mpaa != "null")
                this.txtMPAA.Text = selected.mpaa;
            else
                this.txtMPAA.Text = "";

            string tmpGenres = "";

            foreach (string gen in selected.genres)
                tmpGenres += ", " + gen;

            if(tmpGenres.Length > 2)
                this.txtGenres.Text = tmpGenres.Substring(2);

            //txtMPAA.FontSize = 9;
            //txtMPAA.FontFamily = new FontFamily("Arial");
        }
	}
}